package com.choosefine.springboot.devops.base.service;

import com.choosefine.springboot.devops.activity.dto.UpdateActivityDTO;
import com.choosefine.springboot.devops.activity.model.Activity;
import com.choosefine.springboot.devops.base.config.MapUtil;
import org.beetl.sql.core.SQLManager;
import org.beetl.sql.core.db.KeyHolder;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by dzq on 2017/1/11 0011.
 */
public class BaseService {

    @Autowired
    protected SQLManager sqlManager;

    /*public T selectById(Integer id){
        Map<String,Object> param=new HashMap<String, Object>();
        param.put("id",id);
        Activity result=sqlManager.selectUnique("activity.selectById",param,Activity.class);
        return result;
    }

    public List<Activity> selectList(long pageNum, long pageSize){
        List<Activity> list=sqlManager.select("activity.selectList",Activity.class,null);
        return  list;
    }*/

    public Integer save(Class cla,Map param){
        KeyHolder holder=new KeyHolder();
        Integer result=sqlManager.insert(cla,param,holder);
        Integer resultId=0;
        if(result!=0){
            resultId=Integer.parseInt(holder.getKey().toString());
        }
        return resultId;
    }

    public Integer update(Class cla,Map param){
        Integer result=sqlManager.updateTemplateById(cla, param);//只改我想改的
        return result;
    }

    public Integer falseDelete(Class cla,Map param){
        Integer result=sqlManager.updateTemplateById(cla,param);
        return result;
    }

    public Integer trueDelete(Class cla,Map param){
        Integer result=sqlManager.deleteById(cla,param);
        return result;
    }
}
